﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PhoneBook
{
    /**
     * Class representing a person.
     * @author Occello Audrey
     *
     */
    public class Person : IComparable<Person> {

        private String firstname;
	    private String lastname;
    	
	    /**
	     * @param first is the first name of the person.
	     * @param last is the last name of the person.
	     */
	    public Person(String first, String last) {
		    firstname = first;
		    lastname = last;
	    }

	    public String getFirstname() {
		    return firstname;
	    }

	    public String getLastname() {
		    return lastname;
	    }

        /**
         * Two persons are identical if they hold the same last name and same first name.
         */
        public int CompareTo(Person p)
        {
            if (p.getLastname().Equals(this.getLastname()))
                if (p.getFirstname().Equals(this.getFirstname())) return 0;
                else return getFirstname().CompareTo(p.getFirstname());
            else return getLastname().CompareTo(p.getLastname());            
        }
    	
        /**
         * Two persons are identical if they hold the same last name and same first name.
         */
	    public Boolean equals(Object o) {
		    if (o is Person) return (((Person) o).getLastname().Equals(this.getLastname()) && ((Person) o).getFirstname().Equals(this.getFirstname()));
		    else return false;
	    }
    	
	    /**
	     * Return the last name concatenated to the first name.
	     */
	    public override String ToString() {
		    return firstname + " " + lastname;
	    }    	
    }
}
